<?php

namespace app\agentapi\model;
use think\Cache;
use think\Db;

/**
 *登录模型类
 */
class User extends Base{
    private $token;
    /*
     * 用户登录
     */
    public function agentLogin($phone,$password){
		//验证账户名密码
		$userInfo=Db::table('yoshop_yonghui_user')->where(['phone'=>$phone,'password'=>md5($password)])->field('password',true)->find();
		if(empty($userInfo)){//不存在
			return ['code'=>-1,'data'=>[]];
		}else{
			if($userInfo['status']==2){//禁用
				return ['code'=>-2,'data'=>[]];
			}
			//判断该用户所属公司是否被禁用
            $companyInfo=Db::name('yonghui_company')->where(['id'=>$userInfo['companyId']])->field('id,status')->find();
			if($companyInfo['status']==2){
                return ['code'=>-3,'data'=>[]];
            }
			Cache::set($userInfo['id'],md5($phone.$password),86400 * 7);//登录人token信息
			Cache::set($phone,$userInfo,86400 * 7);//登录人个人信息
			return ['code'=>1,'data'=>$userInfo['id']];
		}
    }
}
